#include "Sphere.h"
#include "GeometricTools.h"


Sphere::Sphere(void)
{
}

Sphere::~Sphere(void)
{
}


bool Sphere::Intersect(Line* line, IntersectInfo *pInfo)
{
    Line lineReflect;

    if ( GeometricTools::LineIntersectSphere(this, line, &pInfo->fPoint, 
        &pInfo->vNormal, pInfo->pMaterial, &lineReflect) )
    {
        // Set the distance
        pInfo->fDistance = Distance(line->GetPos(), pInfo->fPoint);

        // Set the normal, normal of sphere can be calculated directly.
        pInfo->vNormal = Normalize(pInfo->fPoint - GetCenter());

        // Set the material
        pInfo->pMaterial = GetMaterial();
        
        return true;
    }


    return false;
}
